package com.leven.easyerp.dao;

import com.leven.easyerp.util.DESUtils;

/**
 * 自定义的BasicDataSource，增加了密码解密
 * 
 * @author Leven.Chen
 */
public class BasicDataSource extends org.apache.commons.dbcp.BasicDataSource {
	@Override
	public void setPassword(String password) {
		super.setPassword(decrypt(password));
	}

	private String decrypt(String password) {
		try {
			if (password == null || password.length() == 0) {
				return null;
			} else if (password.startsWith("[DES]")) {
				return DESUtils.decrypt(password.substring(5), "MO6_0411");
			} else if (password.startsWith("[NONE]")) {
				return password.substring(6);
			} else {
				return password;
			}
		} catch (Exception e) {
			return password;
		}
	}
}
